package com.banciyuan.bcywebview.biz.main.newdiscover.index.discoverholder;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.base.helper.timelinedatacenter.DetailDataHelper;
import com.banciyuan.bcywebview.base.view.textview.EllipsezeTextView;
import com.banciyuan.bcywebview.utils.string.StringUtil;
import com.banciyuan.bcywebview.utils.universalimageloader.core.ImageLoader;
import com.banciyuan.bcywebview.utils.universalimageloader.utils.ImageOptions;

import de.greenrobot.daoexample.model.Timeline;

/**
 * Created by squall on 2017/6/14.
 */

public class ArticleDiscoverHolder extends BaseDiscoverHolder {

    private ImageView content;
    private TextView title;
    private TextView author;
    private EllipsezeTextView summary;

    public ArticleDiscoverHolder(View itemView) {
        super(itemView);
        content = (ImageView) itemView.findViewById(R.id.ground_content_img);
        title = (TextView) itemView.findViewById(R.id.ground_intro_tv);
        summary = (EllipsezeTextView) itemView.findViewById(R.id.ground_intro_content);
        author = (TextView) itemView.findViewById(R.id.author_name);
    }

    @Override
    public void renderData(final Timeline mItem, final Context mContext) {
        super.renderData(mItem, mContext);
        ImageLoader.getInstance().displayImage(mItem.getContentAddress(), content, ImageOptions.optionsTimeline, null, null, false);
        if (!TextUtils.isEmpty(mItem.getTitle())) {
            title.setVisibility(View.VISIBLE);
            title.setText(Html.fromHtml(mItem.getTitle()));
        } else {
            title.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(mItem.getOUName())) {
            author.setVisibility(View.VISIBLE);
            author.setText(mItem.getOUName());
        } else {
            author.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(mItem.getSummary())) {
            summary.setText(StringUtil.htmlDecoder(mItem.getSummary()));
        } else {
            summary.setText(mContext.getString(R.string.post_article));
        }
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setDiscoverViewClick(mItem, mContext);
            }
        });
    }

    private void setDiscoverViewClick(Timeline mTimeline, Context context) {
        if (null != mTimeline) {
            DetailDataHelper.gotoDailyDetail(context, mTimeline.getUd_id(), false);
        }
    }
}
